package com.chexiehui.jc.ui.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.chexiehui.jc.R;
import com.chexiehui.jc.adapter.FragmentViewPagerAdapter;
import com.chexiehui.jc.base.BaseFragment;
import com.chexiehui.jc.base.BaseLazyLoadFragment;
import com.chexiehui.jc.ui.activity.SearchActivity;
import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;

public class ForumTribuneFragment extends BaseLazyLoadFragment {
    @BindView(R.id.stl_action_table)
    SlidingTabLayout stlActionTable;
    @BindView(R.id.vp_action_pager)
    ViewPager vpActionPager;

    private String[] titles = new String[]{"我的收藏", "车系", "地区", "主题", "热门"};
    private ArrayList<Fragment> actionFragmentList = new ArrayList<>();

    public static ForumTribuneFragment getInstance() {
        ForumTribuneFragment fragment = new ForumTribuneFragment();
        return fragment;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_forum_tribune;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {

       isPrepared = true;
       lazyLoad();
    }

    @Override
    protected void lazyLoad() {
        if(!isVisible || !isPrepared || mHasLoadedOnce){
            return;
        }
        vpActionPager.setOffscreenPageLimit(titles.length);
        actionFragmentList.add(ForumTribuneCollectionFragment.getInstance());
        actionFragmentList.add(ForumTribuneVehicleFragment.getInstance());
        actionFragmentList.add(ForumTribuneAreaFragment.getInstance());
        actionFragmentList.add(ForumTribuneMotifFragment.getInstance());
        actionFragmentList.add(ForumTribuneHotFragment.getInstance());
        vpActionPager.setAdapter(new FragmentViewPagerAdapter(getChildFragmentManager(), actionFragmentList, titles));
        stlActionTable.setViewPager(vpActionPager);
        mHasLoadedOnce = true;
    }

    @OnClick({R.id.ll_head_search})
    public void onViewClicked(View view){
        switch (view.getId()){
            case R.id.ll_head_search:
                startActivity(SearchActivity.class);
                break;
        }
    }

}
